// fenxiao/tixianRecords/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CurrentPage:1,
    items:[],
    loadingMoreHidden:1,
    isHolder: 0
  },

  /** 
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.isHolder==1){
      this.getBrokerageRecordList(options.creatUid);
      this.setData({
        isHolder: options.isHolder
      })
    }else{
      this.GetBrokerageList(this.data.CurrentPage);
    }
  },

  //获取提现记录
  GetBrokerageList: function (CurrentPage){
    var that = this;
    wx.request({
      url: app.globalData.host + '/api/Distributor/GetBrokerageRequestList',
      data: {
        userId: app.globalData.userInfo.Uid,
        page: CurrentPage,
        itemsPerPage: 10
      },
      success: function (res) {
        if (res.data.Code == 0) {
            var items = res.data.Data.Items;
            if (that.data.CurrentPage != 1) {
              var preGoods = that.data.items
              items = preGoods.concat(items);
            }
            for(var i = 0; i < items.length; i++){
              if (items[i].RequestType == 2){
                if (items[i].Remark.indexOf("昵称") != -1){
                  items[i].costNickname = items[i].Remark.match(/昵称:(\S*)/)[1];
                  items[i].costMoney = items[i].Remark.match(/,消费:([\s\S]+?),昵称:/)[1]
                  // items[i].costMoney = items[i].Remark.match(/,消费:([\s\S] +?), 昵称/)[1];
                } else if(items[i].Remark.indexOf("用户") != -1){
                  // items[i].costNickname = items[i].Remark.match(/用户ID:(\S*)/)[1];
                  items[i].costNickname = items[i].Remark.match(/用户ID:([\s\S]+?),消费:/)[1];
                  items[i].costMoney = items[i].Remark.match(/消费:(\S*)/)[1];
                }
              }
            }
            that.setData({
              items: items,
              loadingMoreHidden: res.data.Data.TotalPages
            })
        } else {
          wx.showModal({
            title: '错误',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  },
  // 加载更多
  loadMore: function (e) {
    var that = this;
    if (that.data.loadingMoreHidden > 1 && that.data.CurrentPage < that.data.loadingMoreHidden){
      var currPage = that.data.CurrentPage;
      that.setData({
        CurrentPage: currPage + 1
      })
      that.GetBrokerageList(that.data.CurrentPage);
    }else{
      return
      }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  // 股东提现记录
  getBrokerageRecordList: function (createUid){
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Shareholder/GetRequestList',
      data:{
        createUid: createUid,
        uid: app.globalData.userInfo.Uid,
        page: that.data.CurrentPage
      },
      success: function (res) {
        if (res.data.Code == 0) {
          var items = res.data.Data.List;
          if (that.data.CurrentPage != 1) {
            var preGoods = that.data.items
            items = preGoods.concat(items);
          }
          that.setData({
            items: items,
            loadingMoreHidden: res.data.Data.PageModel.TotalPages
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  }
})